package com.itheima.homework01.listdemo01;

import java.util.ArrayList;
import java.util.Iterator;

public class ArrayListDemo1 {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(5);
        //1. 自增for循环遍历
        for (int i = 0; i < arrayList.size(); i++) {
            int num = arrayList.get(i);
            System.out.println(num);
        }
        System.out.println("---------------------------");
        //2. 迭代器遍历
        Iterator<Integer> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Integer num = iterator.next();
            System.out.println(num);
        }
        System.out.println("-----------------------------");
        //3. 增强for循环遍历
        for (Integer num : arrayList) {
            System.out.println(num);
        }
    }
}
